package de.reondo.jos;

import org.jgrapht.Graph;

public class ClassGraphStyler implements IGraphStyler<Class<?>, ClassDependencyEdge> {

	private Graph<Class<?>, ClassDependencyEdge> graph;
	private int maxNumberOfEdges;

	public ClassGraphStyler(Graph<Class<?>, ClassDependencyEdge> graph) {
		this.graph = graph;
		Class<?> maxEdgeVertex = GraphUtils.getVertexWithMaximumEdges(graph);
		maxNumberOfEdges = 0;
		if (maxEdgeVertex != null) {
			maxNumberOfEdges = graph.edgesOf(maxEdgeVertex).size();
		}
	}
	
	@Override
	public String getColorForVertex(Class<?> vertex) {
		double d = graph.edgesOf(vertex).size() / (maxNumberOfEdges + 1.0) * 9;
		int i = ((int) Math.floor(d)) + 1;
		return ""+i;
	}
	

	@Override
	public String getVertexLabel(Class<?> vertex) {
		return vertex.getPackage().getName() + "\\n" + vertex.getSimpleName();
	}

	@Override
	public String getEdgeLabel(ClassDependencyEdge edge) {
		return edge.getType().getShortName();
	}

}
